# - Find LevelDB
# Find the LevelDB includes and library
#
# This module defines
#  LEVELDB_INCLUDE_DIR, where to find leveldb/db.h, etc.
#  LEVELDB_LIBRARIES, the libraries needed to use LevelDB.
#  LEVELDB_FOUND, If false, do not try to use LevelDB.
#
# Also defines these cache variables:
#  LEVELDB_INCLUDE_DIR, the directory where leveldb/db.h is located.
#  LEVELDB_LIBRARY, the path to the LevelDB library.
#  LEVELDB_LIBRARY_DEBUG, the path to the debug LevelDB library (if any).

# Find the header file
find_path(LEVELDB_INCLUDE_DIR
  NAMES leveldb/db.h
  PATHS
    /usr/include
    /usr/local/include
    /opt/local/include
    /sw/include
    ${LEVELDB_ROOT}/include
  DOC "LevelDB include directory"
)

# Find the library
find_library(LEVELDB_LIBRARY
  NAMES leveldb
  PATHS
    /usr/lib
    /usr/lib64
    /usr/local/lib
    /usr/local/lib64
    /opt/local/lib
    /sw/lib
    ${LEVELDB_ROOT}/lib
  DOC "LevelDB library"
)

# Optionally find debug library
find_library(LEVELDB_LIBRARY_DEBUG
  NAMES leveldbd leveldb
  PATHS
    /usr/lib
    /usr/lib64
    /usr/local/lib
    /usr/local/lib64
    /opt/local/lib
    /sw/lib
    ${LEVELDB_ROOT}/lib
  DOC "LevelDB debug library"
)

# Handle the QUIETLY and REQUIRED arguments and set LEVELDB_FOUND
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LevelDB DEFAULT_MSG
  LEVELDB_LIBRARY
  LEVELDB_INCLUDE_DIR
)

# Set the output variables
if(LEVELDB_FOUND)
  set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY})
  set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR})
  
  # Mark as advanced
  mark_as_advanced(
    LEVELDB_INCLUDE_DIR
    LEVELDB_LIBRARY
    LEVELDB_LIBRARY_DEBUG
  )
endif()

# For compatibility with some packages
set(LEVELDB_FOUND ${LevelDB_FOUND})